package com.nintendo.controller;

import com.nintendo.dto.DocDTO;
import com.nintendo.entity.Doc;
import com.nintendo.response.Result;
import com.nintendo.service.DocService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/doc")
@CrossOrigin
@Slf4j
public class DocController {
    @Autowired
    private DocService docService;
    @GetMapping("/findAllDoc")
    public Result findAllDoc(){
        return Result.ok().put("data",docService.findAll());
    }
    @PostMapping("/byNameAuthPage")

    public Result findByNameAuthPage(@RequestBody DocDTO docDTO){
        log.info("docDTO======>,{}",docDTO);

        return Result.ok().put("data",docService.findByNameAuthPage(docDTO));
    }
    @PutMapping("/updateById")
    public Result updateDocById(@RequestBody Doc doc){
        docService.updateDocById(doc);
        return Result.ok("修改成功");
    }
    @DeleteMapping("/{id}")
    public Result deleteDocById(@PathVariable("id")Long id){
        docService.deleteDocById(id);
        return Result.ok("删除成功");
    }
    @GetMapping("/{id}")
    public Result findDocById(@PathVariable("id")Long id){
        return Result.ok().put("data",docService.findDocById(id));
    }
    @PostMapping("/saveDoc")
    public Result saveDoc(@RequestBody Doc doc){
        docService.saveDoc(doc);
        return Result.ok("添加成功");
    }
    @GetMapping("/all/{id}")
    public Result findDocItemsById(@PathVariable("id")Long id){
        return Result.ok().put("data",docService.findDocItemsById(id));
    }
    @DeleteMapping("/del")
    public Result deleteAllKeys(@RequestBody Map<String,Object> entity) {
        List<Long> ids = (List<Long>) entity.get("ids");
        docService.deleteDocByIds(ids);
        return Result.ok("删除成功");
    }
}
